#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>
#include <map>

using namespace std;

class Solution {
public:
    bool rotateString(string s, string goal) {
        int sLen = s.length();
        int goalLen = goal.length();
        if (sLen != goalLen) {
            return false;
        }

        string sNew = s;
        auto pos = sNew.find(goal[0]);
        while (pos != string::npos) {
            /* 前判断后半部分是否相同 */
            string sTail = sNew.substr(pos);
            string goalHead = goal.substr(0, sTail.length());
            if (sTail == goalHead) {
                string sHead = s.substr(0, sLen - sTail.length());
                string goalTail = goal.substr(sTail.length());
                if (sHead == goalTail) {
                    return true;
                }
            }

            sNew = sNew.substr(pos + 1);
            pos = sNew.find(goal[0]);
        }

        return false;
    }
};

int main()
{   
    Solution s;
    string str1 = "abcdeadcbe";
    string str2 = "adcbeabcde";
    cout << boolalpha << s.rotateString(str1, str2) << endl;
    return 0;
}